<?php


namespace Api\Controller;

/**
 * @apiDefine ApiErrorExample
 *
 * @apiErrorExample 失败返回
 * HTTP/1.1 200 OK
 * {
 *  "code": "",
 *  "info": "",
 *  "data": "",
 * }
 *
 */

/**
 * @apiDefine ApiSuccessExample
 *
 * @apiSuccessExample 成功返回
 * HTTP/1.1 200 OK
 * {
 *  "data": "",
 *  "info": "",
 *  "code": 200,
 * }
 * 
 */

/** 
 * 广告接口
 * @author Legend. <xcx_legender@qq.com>
 * @param 
 * @return 
 */

class AdController extends PublicController 
{

	// 获取某一个广告位的全部广告
	/**
	 * @api {get}  /api/Ad/all 获取广告位的广告
	 * @apiVersion 4.0.0
	 * @apiName all
	 * @apiGroup Ad
	 *
	 * @apiParam {String} code 广告位标识
	 *
	 * @apiSuccess {String} info  show message
	 * @apiSuccess {Number} code  status code.
	 * @apiSuccess {Object} data  extend datas.
	 * @apiSuccess {Number} data.count  数据条数
	 * @apiSuccess {List} data.lists  广告位下所有广告数据列表[]
	 * @apiSuccess {String} data.lists.image   广告图片网址
	 * @apiSuccess {String} data.lists.link    广告图片链接地址
	 * @apiSuccess {Number} data.lists.id      广告ID
	 *
	 * @apiUse ApiSuccessExample
	 *
	 * @apiUse ApiErrorExample
	 */
	
	public function all($code = '')
	{
		if ($code == 'appbanner') {
			$code = 'toolbanner';
		}
		$ads = event('Ad')->getAdsByCode($code);
		if ($ads)
		{
			$ads = field_filter($ads, ['image', 'link', 'id'], true, ['image']);
		}
		$data = [
			'count' => count($ads),
			'lists'  => $ads ?:[],
		];
		$this->success('', $data);
	}

}